#include<bits/stdc++.h>
using namespace std;
int n,m,t,a[100001],b[100001],c[100001],d[100001],e[100001],f[100001],ans[50005],cnt,tmp,sum,g=1,k=1;
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>m;
    while(sum<=n){
        sum*=2;
        g++;
    }
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    for(int i=1;i<=k;i++)cin>>tmp;
    cin>>t;
    for(int i=1;i<=t;i++){
        sum=1;
        cin>>c[i]>>d[i]>>e[i]>>f[i];
    }
    for(int i=1;i<=k;i++){
        for(int j=1;j<=sizeof(c);j++){
            if(tmp&&a[j/2]>g)ans[++cnt]=a[j/2];
        }
        cout<<ans[i];
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
